//=========================================================
// ClockTimer.cpp
//
// Implement member functions in ClockTimer class which
// is in file ClockTimer.h
//=========================================================

#include "cppTutorConcreteSubjectClockTimer.h"

#ifndef WIN32
#include <time.h>
#endif

#include <stdlib.h>

void ClockTimer::Tick() 
{
/* 
 * Set time zone from TZ environment variable. If TZ is not set,
 * the operating system is queried to obtain the default value
 * for the variable.
 */
    #ifdef WIN32
    _tzset ();
    #else
    tzset ();
    #endif

    /* Obtain operating system-style time. */
    #ifdef WIN32
    _strtime ( tmpbuf );  // tmpbuf = current system time
    #else
    strtime ();
    #endif
    Notify();
}

int ClockTimer::GetHour()
{
     char timebuf[128]; // temp. buffer
     strncpy(timebuf, tmpbuf, 2);
     timebuf[2] = NULL;
     
     return atoi(timebuf);
}

int ClockTimer::GetMinute()
{
     char timebuf[128]; // temp. buffer
     strncpy(timebuf, tmpbuf+3, 2);
     timebuf[2] = NULL;

     return atoi(timebuf);
}

int ClockTimer::GetSecond()
{
     char timebuf[128]; // temp. buffer
     strncpy(timebuf, tmpbuf+6, 2);
     timebuf[2] = NULL;

     return atoi(timebuf);
}

#ifndef WIN32
void ClockTimer :: strtime ()
{
     time_t rawtime;
     struct tm * timeinfo;
     //char buffer [80];

     time (&rawtime);
     timeinfo = localtime (&rawtime);

     //strftime (buffer,80,"%I:%M:%S%p.",timeinfo);
     //strftime (buffer,80,"%I:%M:%S",timeinfo);
     strftime (tmpbuf,80,"%I:%M:%S",timeinfo);
     //puts (buffer);
}
#endif
        